package com.fedex.longitude.dialog;

import org.eclipse.jface.dialogs.Dialog;
import org.eclipse.jface.dialogs.IDialogConstants;
import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Text;

public class LoginDialog extends Dialog {

	private Text _userId, _password;

	public LoginDialog(Shell parent) {
		super(parent);
	}

	@Override
	protected void configureShell(Shell newShell) {
		super.configureShell(newShell);
		newShell.setText("FedEx Longitude Login");
	}

	@Override
	protected Control createDialogArea(Composite parent) {
		Composite composite = new Composite(parent, SWT.NONE);
		GridLayout layout = new GridLayout(2, false);
		layout.marginWidth = 20;
		composite.setLayout(layout);

		Label userIdLabel = new Label(composite, SWT.NONE);
		userIdLabel.setText("FedEx ID");
		userIdLabel.setLayoutData(new GridData(SWT.BEGINNING, SWT.CENTER,
				false, false));

		_userId = new Text(composite, SWT.BORDER);
		GridData userIdData = new GridData(SWT.FILL, SWT.FILL, true, false);
		userIdData.widthHint = 180;
		_userId.setLayoutData(userIdData);

		Label passwordLabel = new Label(composite, SWT.NONE);
		passwordLabel.setText("Password");
		passwordLabel.setLayoutData(new GridData(SWT.BEGINNING, SWT.CENTER,
				false, false));

		_password = new Text(composite, SWT.BORDER | SWT.PASSWORD);
		_password.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false));

		return composite;
	}

	@Override
	protected void createButtonsForButtonBar(Composite parent) {
		createButton(parent, IDialogConstants.OK_ID, "&Login", true);
		createButton(parent, IDialogConstants.CANCEL_ID,
				IDialogConstants.CANCEL_LABEL, false);
	}

	@Override
	protected void okPressed() {
		// TODO: implement a true login process using LDAP
		// if(isBlank(_userId.getText()) || isBlank(_password.getText())){
		// MessageDialog.openError(getShell(), "Invalid Login",
		// "Ivalid FedEx ID and/or Password");
		// return;
		// }
		super.okPressed();
	}
}
